package com.neuedu.validation.controller;


import com.neuedu.entity.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {


    /**
     * http://127.0.0.1/user/save?age=18
     * @param user
     * @return
     */
    @GetMapping("/save")
    User save(@Validated User user , BindingResult result){
        List<ObjectError> list = result.getAllErrors();
        for (ObjectError objectError : list) {
            System.out.println(objectError.getDefaultMessage());
        }
        return user;
    }




}
